<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        var fn = (function fum() {
            var num = 20;
            num++;
            function foo() {
                return num;

            }
            return foo;
        })();
        console.log(fn());

        var obj = (function createPerson() {
            var name = '姓名', age = 10;
            return {
                setName: function (newName) {
                    name = newName;
                },
                getName: function () {
                    return name;
                }
            }
        })();

        obj.setName('刘德华');
        console.log(obj.getName());
    </script>
</body>

</html>